package com.zdp.middleware.ratelimiter.test.interfaces;

import com.zdp.middleware.hystrix.annotation.DoHystrix;
import com.zdp.middleware.interfaces.UserInfo;
import com.zdp.middleware.ratelimiter.annotation.DoRateLimiter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author ZhengDp
 * @Date 2023/5/26 19:07
 */
@RestController("RateLimiterBean")
@RequestMapping("/ratelimiter")
public class UserController {

    private Logger logger = LoggerFactory.getLogger(UserController.class);

    @DoRateLimiter(permitsPerSecond = 1,returnJson = "{\n" +
            "\"code\":\"1111\",\n" +
            "\"info\":\"调用方法超过最大次数，限流返回！\"\n" +
            "}")
    @RequestMapping(value = "/api/queryUserInfo",method = RequestMethod.GET)
    public UserInfo queryUserInfo(@RequestParam String userId) throws InterruptedException {
        logger.info("查询用户信息,userId : {}",userId);
        //Thread.sleep(1000);
        return new UserInfo("郑达平:" + userId,19,"福建省泉州市惠安县");
    }

}
